package work20241216.homework;

/**
 * @author zdl
 * @date 2024/12/16
 */

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 使用ArrayList() 写，不调用静态方法
 */
public class DemoKTV3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        List<String> list = new ArrayList<>();
        list.add("奇迹再现");
        list.add("月空中最亮的星");
        list.add("姐就是女王");
        list.add("甜蜜蜜");
        list.add("月半小夜曲");

        System.out.println("-------------欢迎来到点歌系统-------------");
        System.out.println("初始歌曲列表:" + list);
        boolean flag = true;
        while (flag) {
            System.out.println("0.添加歌曲至列表");
            System.out.println("1.将歌曲置顶");
            System.out.println("2.将歌曲前移一位");
            System.out.println("3.退出");
            System.out.print("请输入要执行的操作标号:");
            int num = sc.nextInt();
            switch (num) {
                case 0:
                    System.out.println("请输入要添加的歌曲名称:");
                    String songName = sc.next();
                    if (list.contains(songName)) {
                        System.out.println("歌曲已存在！");
                    } else {
                        list.add(songName);
                        System.out.println("添加后歌曲列表:" + list);
                    }
                    break;
                case 1:
                    System.out.println("请输入要置顶的歌曲名称:");
                    String songName1 = sc.next();
                    if (list.contains(songName1)){
                        list.remove(songName1);
                        list.add(0,songName1);
                        System.out.println("置顶后歌曲列表:" + list);
                    }else {
                        System.out.println("您输入的《" + songName1 + "》歌曲不存在,无法置顶");
                    }
                    break;
                case 2:
                    System.out.println("请输入要置前的歌曲名称:");
                    String songName2 = sc.next();
                    if (list.contains(songName2)){
                        int index = list.indexOf(songName2);
                        if (index == 0){
                            System.out.println("《"+songName2+"》已经是置顶位置了！");
                        }else {
                            list.remove(songName2);
                            list.add(index-1,songName2);
                            System.out.println("前移一位后歌曲列表:" + list);
                        }
                    }else {
                        System.out.println("您输入的《" + songName2 + "》歌曲不存在,无法前移一位");
                    }
                    break;
                case 3:
                    System.out.println("-------------------退出----------------");
                    flag = false;
                    break;
                default:
                    System.out.println("请输入正确的操作编号(0-3)!!!");
                    flag = false;
            }
        }
    }


}
